import 'package:backend.core/core/domain/entities/web/web_one_time_purchase_item.dart';
import 'package:backend.core/core/domain/entities/web/web_purchase_item.dart';
import 'package:backend.core/core/domain/entities/web/web_subscription.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_one_time_purchase_item_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_purchase_item_dto.dart';
import 'package:backend.purchases/infrastructure/dtos/api/web/api_web_subscription_dto.dart';

class ApiWebPurchaseItemDtoFactory {
  const ApiWebPurchaseItemDtoFactory._internal();

  static const _instance = ApiWebPurchaseItemDtoFactory._internal();

  factory ApiWebPurchaseItemDtoFactory() {
    return _instance;
  }

  ApiWebPurchaseItemDto fromEntity(WebPurchaseItem purchaseItem) {
    if (purchaseItem is WebSubscription) {
      return ApiWebSubscriptionDto.fromEntity(purchaseItem);
    }

    if (purchaseItem is WebOneTimePurchaseItem) {
      return ApiWebOneTimePurchaseItemDto.fromEntity(purchaseItem);
    }

    throw UnimplementedError();
  }
}
